package com.linewell.license.demo.security;

import com.linewell.license.demo.model.User;
import com.linewell.license.demo.utils.CurrentRequestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* @author
* Company:
* Createtime : 2018年9月24日 下午3:23:16
* Description : session 过期过滤器
*/
public class SecurityExpiredSessionFilter implements Filter {

	private Logger logger = LoggerFactory.getLogger(SecurityExpiredSessionFilter.class);

	@Override
	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
		User info = CurrentRequestUtils.getLoginInfo(request);
        if(info != null) {
        	chain.doFilter(request, response);
        	return;
        }
		logger.debug(request.getRequestURI());
        CurrentRequestUtils.sendRedirect(request , response ,"/loginOut.html");
	}

}
